<template>
  <Table
    ref="tableRef"
    :url="URL_QUERYEQUIPMENTBRAND"
    :columns="data.columns"
    :handles="data.handles"
    :toolbar="data.toolbar"
    :query="data.query"
  ></Table>
  <DialogBrand ref="dialogBrandRef" @getData="getData1"></DialogBrand>
</template>

<script lang="ts" setup name="brandManagementList">
import Table from '@/components/table/index.vue';
import DialogBrand from '../components/dialogBrand.vue';
import {
  URL_QUERYEQUIPMENTBRAND,
  pageQueryEquipmentBrand,
} from '@/service/apis/config';

const tableRef = ref();
const dialogBrandRef = ref();

const emit = defineEmits(['get-update']);
onActivated(() => {
  emit('get-update', (flag: boolean) => {
    if (flag) {
      tableRef.value?.getData();
    }
  });
});

const data = reactive({
  id: '',
  columns: [
    {
      prop: 'brandName',
      label: '品牌名称',
    },
    {
      prop: 'createTime',
      label: '创建时间',
    },
  ],
  handles: [
    {
      label: '修改',
      permission: 'brandManagementList.edit',
      handle: (row: any) => {
        dialogBrandRef.value?.show(row);
      },
    },
  ],
  toolbar: [
    {
      label: '新增',
      permission: 'brandManagementList.add',
      icon: 'icon-add',
      type: 'primary',
      handle: (row: any) => {
        console.log(dialogBrandRef.value);
        dialogBrandRef.value?.show('');
      },
    },
  ],
  query: [
    {
      label: '品牌名称',
      prop: 'brandName',
      comName: 'input',
      props: {
        placeholder: '请输入品牌名称',
      },
    },
    {
      label: '创建时间',
      prop: 'date',
      comName: 'date',
      keys: ['startTime', 'endTime'],
      props: {
        type: 'daterange',
      },
    },
  ],
});

const getData1 = (page: any) => {
  pageQueryEquipmentBrand({}, page).then((res: any) => {
    if (res) {
      nextTick(() => {
        tableRef.value?.setTable({
          total: res.totalCount,
          table: res.dataList,
        });
      });
    }
  });
};
</script>